package demo1;

import java.util.Stack;

class MyQueue {

    Stack<Integer> stack1 ;
    Stack<Integer> stack2 ;

    public MyQueue() {
        stack1 = new Stack<>() ;
        stack2 = new Stack<>();

    }
    
    public void push(int x) {
      stack1.push(x);

    }
    
    public int pop() {
        if(empty()){
            return -1;
        }
      if(stack2.isEmpty()){
          int size = stack1.size();
          for (int i = 0; i < size-1; i++) {
              stack2.push(stack1.pop());
          }
          return stack1.pop();
      }
    return stack2.pop();

    }
    
    public int peek() {
        if(empty()){
            return -1;
        }
        if(stack2.isEmpty()){
            int size = stack1.size();
            int tmp = 0;
            for (int i = 0; i < size; i++) {
                tmp = stack1.pop();
                stack2.push(tmp);
            }
            return tmp;
        }
        return stack2.peek();


    }
    
    public boolean empty() {
        return stack1.isEmpty() && stack2.empty();

    }
}
